//
//  ProductCodeCell.m
//  
//
//  Created by Abner on 16/4/28.
//
//

#import "ProductCodeCell.h"

@interface ProductCodeCell ()
{
    UIView *_topLine; //cell最上面的线，UI要求的，只有indexPath.row == 0时显示；
}
@end
@implementation ProductCodeCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _topLine = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 1)];
        _topLine.backgroundColor = SetColorRGBValue(0xe0e0e0, 1.0);
        _topLine.alpha = 0.5;
        [self.contentView addSubview:_topLine];
        
        self.proCodeLb = [[UILabel alloc]init];
        [self.contentView addSubview:self.proCodeLb];
        self.proCodeLb.font = KAddLeftLbFont;
        self.proCodeLb.textColor = KAddLeftLbColor;
        self.proCodeLb.frame = CGRectMake(10, 0, 80, 44);
        self.proCodeLb.text = @"商品编号";
        
        self.proCodeTf = [[UITextField alloc]init];
        [self.contentView addSubview:self.proCodeTf];
        self.proCodeTf.placeholder = @"请输入商品编号";
        self.proCodeTf.textColor = KAddLeftLbColor;
        self.proCodeTf.font = KAddLeftLbFont;
        self.proCodeTf.clearButtonMode = UITextFieldViewModeWhileEditing;
        [self.proCodeTf addTarget:self action:@selector(proCodeTfClicked) forControlEvents:UIControlEventEditingChanged];
        self.proCodeTf.frame = CGRectMake(90, 0, ScreenWidth-130, 44);
        
        self.proCodeBt = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:self.proCodeBt];
        self.proCodeBt.frame = CGRectMake(ScreenWidth-40, 0, 40, 44);
        [self.proCodeBt setImage:[UIImage imageNamed:@"saoma_icon"] forState:UIControlStateNormal];
        [self.proCodeBt setImage:[UIImage imageNamed:@"saoma_icon"] forState:UIControlStateHighlighted];
        [self.proCodeBt setImageEdgeInsets:UIEdgeInsetsMake(12, 10, 12, 10)];
        [self.proCodeBt addTarget:self action:@selector(codeBTClicked) forControlEvents:UIControlEventTouchUpInside];
        
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0,44, ScreenWidth, 1)];
        line.backgroundColor = SetColorRGBValue(0xe0e0e0, 1.0);
        line.alpha = 0.5;
        [self.contentView addSubview:line];
    }
    return self;
}

-(void)codeBTClicked
{
    LCLog(@"点击扫码按钮了");
    if ([self.delegate respondsToSelector:@selector(codeBtClicked)]) {
        [self.delegate codeBtClicked];
    }
}

-(void)proCodeTfClicked
{
    if (self.proCodeTfClickedBlock) {
        self.proCodeTfClickedBlock(self);
    }
}


+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *indetifier = @"ProductCodeCellIdentifier";
    ProductCodeCell *cell = [tableView dequeueReusableCellWithIdentifier:indetifier];
    if (!cell) {
        cell = [[ProductCodeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indetifier];
    }
    return cell;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
